package com.heima.utils.common;

/**
 * 存入用户id到ThreadLocal中
 */
public class UserContext {
    private static final ThreadLocal<Long> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 将用户id存入ThreadLocal中
     * @param id
     */
    public static void setUserId(Long id) {
        THREAD_LOCAL.set(id);
    }

    /**
     * 从ThreadLocal中取出usesrID
     */
    public static Long getUserId() {
        return THREAD_LOCAL.get();
    }

    /**
     * 从ThreadLocal中删除userId
     */
    public static void removeUserId() {
        THREAD_LOCAL.remove();
    }
}
